﻿@model KL.Store.Web.Models.SatisSiparisDetayModel
@using KL.Store.Core
@{
    ViewBag.Title = "eStore PDF Export";
    Layout = "~/Views/Shared/_LayoutPDF.cshtml";
    string TeslimatTipi = "";
    switch (Model.SiparisBilgi.TeslimSekli)
    {
        case "D": TeslimatTipi = "Depo Teslim"; break;
        case "K": TeslimatTipi = "Kargo"; break;
        case "S": TeslimatTipi = "Sevkiyat"; break;
        case "N": TeslimatTipi = "Nakliye"; break;
        default: ; break;
    }

    string TeslimatTipi2 = "";
    switch (Model.SiparisBilgi.TeslimSekli)
    {
        case "D": TeslimatTipi2 = "Depo Teslim"; break;
        case "K": TeslimatTipi2 = Parameters.CargoList.Where(c => c.CargoId == Model.SiparisBilgi.KargoId).FirstOrDefault() != null ? Parameters.CargoList.Where(c => c.CargoId == Model.SiparisBilgi.KargoId).FirstOrDefault().CargoName : "Kargo"; break;
        case "S": TeslimatTipi2 = "Sevkiyat"; break;
        case "N": TeslimatTipi2 = "Nakliye"; break;
        default: ; break;
    }
}
<div class="col-xs-12 first last">
    <div class="col-xs-7 first last">
        <table class="table table-bordered">
            <tr>
                <td>Sip.No:</td>
                <td>@Model.SiparisBilgi.SiparisId</td>
                <td>Tarih:</td>
                <td>@Model.SiparisBilgi.Tarih</td>
                <td>Tes.Tarihi:</td>
                <td>@Model.SiparisBilgi.TeslimTar</td>
            </tr>
            <tr>
                <td>Cari No:</td>
                <td>@Model.SiparisBilgi.CariId</td>
                <td colspan="4">@Model.SiparisBilgi.CariAdi</td>
            </tr>
            <tr>
                <td>Açıklama:</td>
                <td colspan="5">@Model.SiparisBilgi.Aciklama</td>
            </tr>
        </table>
    </div>
    <div class="col-xs-5 first last">
        <table class="table table-bordered">
            <tr>
                <td>Ödeme Şekli:</td>
                <td>@Model.SiparisBilgi.OdemeSekli</td>
                <td>@(Model.OdemeSekilleri.Where(o => o.Kisa == Model.SiparisBilgi.OdemeSekli).FirstOrDefault().Uzun)</td>
            </tr>
            <tr>
                <td>Teslim Şekli:</td>
                <td>@Model.SiparisBilgi.TeslimSekli</td>
                <td>@(TeslimatTipi)</td>
            </tr>
            <tr>
                <td>Sipariş Durum::</td>
                <td colspan="2">@(Model.SiparisDurumlari.Where(s => s.DurumId == Model.SiparisBilgi.DurumId).FirstOrDefault().Aciklama)</td>
            </tr>
        </table>
    </div>
    <div class="col-xs-12 first last">
        <table class="table table-bordered">
            <thead>
                <tr>
                    <td>#</td>
                    <td>Stok No</td>
                    <td>Stok Adı</td>
                    <td>Varyant</td>
                    <td>Depo</td>
                    <td>Br</td>
                    <td>Mik.</td>
                    <td>Tes.</td>
                    <td>İpt.</td>
                    <td>Kal.</td>
                    <td>P.Cins</td>
                    <td>Birim Fiyat</td>
                    <td>Kdv%</td>
                    <td>İsk%</td>
                    <td>Genel Toplam</td>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.SatisDetay)
                {
                    <tr>
                        <td>@(item.SatirNo)</td>
                        <td>@(item.StokId)</td>
                        <td>@(item.Aciklama)@(!string.IsNullOrEmpty(item.Model) ? " - " + item.Model : "")</td>
                        <td>@(item.VariantValue)</td>
                        <td>@(item.DepoId)</td>
                        <td>@(item.StokBirim)</td>
                        <td>@(item.StokMiktar.ToString("###,###,##0"))</td>
                        <td style="color: #53874c; font-weight: bold;">@(item.MiktarTeslim > 0 ? item.MiktarTeslim.ToString("###,###,##0") : "")</td>
                        <td style="color: #d54f4f; font-weight: bold;">@(item.MiktarIptal > 0 ? item.MiktarIptal.ToString("###,###,##0") : "")</td>
                        <td style="color: #4e5494; font-weight: bold;">@(item.MiktarKalan > 0 ? item.MiktarKalan.ToString("###,###,##0") : "")</td>
                        <td>@(item.ParaCins)</td>
                        <td>@(item.BirimFiyat)</td>
                        <td>@(item.KdvOrani.ToString("###,###,##0"))</td>
                        <td>@(item.Iskonto)</td>
                        <td>@(item.GenelToplam)</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="col-xs-7 first">
        <table class="table table-bordered">
            <tr>
                <td>Teslimat: <b>@(TeslimatTipi2)</b></td>
                <td>
                    <b>@Html.Raw(Model.SiparisBilgi.FaturaSiparisIle ? "Fatura Sipariş İle Birlikte" : "<span style=\"color:#ee1111\">Fatura Siparişten Ayrı</span>")</b>
                </td>
            </tr>
        </table>
        @{
            var tblw = "50%";
            if (Model.SiparisAdresler.Count() == 1)
            {
                tblw = "100%";
            }
        }
        @if (Model.SiparisAdresler.Count() > 0)
        {
            var BirinciAdres = Model.SiparisAdresler.Where(a => a.AddressType == "CAR").FirstOrDefault();
            <table class="table table-bordered" style="width:@(tblw); float:left;">
                <thead>
                    <tr>
                        <td>Kargo Adresi
                        </td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Firma / Ad Soyad: <b>@BirinciAdres.Name</b></td>
                    </tr>
                    <tr>
                        <td>Vergi Dairesi/No: <b>@BirinciAdres.TaxOffice @BirinciAdres.TaxNo</b></td>
                    </tr>
                    <tr>
                        <td>Telefon: <b>@BirinciAdres.Phone</b></td>
                    </tr>
                    <tr>
                        <td>Adres 1: <b>@BirinciAdres.Address1</b></td>
                    </tr>
                    <tr>
                        <td>Adres 2: <b>@BirinciAdres.Address2</b></td>
                    </tr>
                    <tr>
                        <td>Posta Kodu: <b>@BirinciAdres.PostalCode</b></td>
                    </tr>
                    <tr>
                        <td>İlçe: <b>@BirinciAdres.County</b></td>
                    </tr>
                    <tr>
                        <td>İl: <b>@Parameters.CityList.Where(c => c.CityId == BirinciAdres.City).FirstOrDefault().CityName</b></td>
                    </tr>
                </tbody>
            </table>
        }
        @if (Model.SiparisAdresler.Count() > 1)
        {
            var BirinciAdres = Model.SiparisAdresler.Where(a => a.AddressType == "CAR").FirstOrDefault();
            var IkinciAdres = Model.SiparisAdresler.Where(a => a.AddressType == "INV").FirstOrDefault();
            var UniqueAddresses = (BirinciAdres.Address1 != IkinciAdres.Address1 || BirinciAdres.Name != IkinciAdres.Name) ? true : false;
            var addresUniqColor = UniqueAddresses ? "#ee1111" : "";
            <table class="table table-bordered" style="width:@(tblw); float:left;">
                <thead>
                    <tr>
                        <td@{if (UniqueAddresses)
                             {<text> style="color:@(addresUniqColor);"</text> }}>Fatura Adresi</td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Firma / Ad Soyad: <b>@IkinciAdres.Name</b></td>
                    </tr>
                    <tr>
                        <td>Vergi Dairesi/No: <b>@IkinciAdres.TaxOffice @IkinciAdres.TaxNo</b></td>
                    </tr>
                    <tr>
                        <td>Telefon: <b>@IkinciAdres.Phone</b></td>
                    </tr>
                    <tr>
                        <td>Adres 1: <b>@IkinciAdres.Address1</b></td>
                    </tr>
                    <tr>
                        <td>Adres 2: <b>@IkinciAdres.Address2</b></td>
                    </tr>
                    <tr>
                        <td>Posta Kodu: <b>@IkinciAdres.PostalCode</b></td>
                    </tr>
                    <tr>
                        <td>İlçe: <b>@IkinciAdres.County</b></td>
                    </tr>
                    <tr>
                        <td>İl: <b>@Parameters.CityList.Where(c => c.CityId == IkinciAdres.City).FirstOrDefault().CityName</b></td>
                    </tr>
                </tbody>
            </table>
        }
    </div>
    <div class="col-xs-5 first last right">
        <table class="table table-bordered">
            <tr>
                <td>Toplam Tutar</td>
                <td class="alignright">@Model.SiparisBilgi.ToplamTutar</td>
            </tr>
            <tr>
                <td>İskonto Tutarı</td>
                <td class="alignright">@Model.SiparisBilgi.IskontoTutar</td>
            </tr>
            <tr>
                <td>Ara Toplam</td>
                <td class="alignright">@Model.SiparisBilgi.AraToplam</td>
            </tr>
            <tr>
                <td>KDV Tutarı</td>
                <td class="alignright">@Model.SiparisBilgi.KdvTutar</td>
            </tr>
            <tr>
                <td>Genel Tutar</td>
                <td class="alignright">@Model.SiparisBilgi.GenelToplam</td>
            </tr>
        </table>
    </div>
    <div class="col-xs-12 first last">
        <table class="table table-bordered">
            @if (!string.IsNullOrEmpty(Model.SiparisBilgi.Aciklama))
            {
                <tr>
                    <td style="width: 20%;">Açıklama</td>
                    <td><strong>@Model.SiparisBilgi.Aciklama</strong></td>
                </tr>
            }
            @if (!string.IsNullOrEmpty(Model.SiparisBilgiFatura.BankName))
            {
                <tr>
                    <td style="width: 20%;">Banka Adı</td>
                    <td><strong>@Model.SiparisBilgiFatura.BankName</strong></td>
                </tr>
            }
            <tr>
                <td style="width: 20%;">Taksit Sayısı</td>
                <td><strong>@Model.SiparisBilgiFatura.InstallmentNo</strong></td>
            </tr>
            @if (!string.IsNullOrEmpty(Model.SiparisBilgiFatura.Info))
            {
                <tr>
                    <td style="width: 20%;">Bilgi</td>
                    <td><strong>@Model.SiparisBilgiFatura.Info</strong></td>
                </tr>
            }
            @if (!string.IsNullOrEmpty(Model.SiparisBilgiFatura.Comment))
            {
                <tr>
                    <td style="width: 20%;">Yorum/Not/OrderNo</td>
                    <td><strong>@Model.SiparisBilgiFatura.Comment</strong></td>
                </tr>
            }
        </table>
    </div>
</div>
